package com.iptv.grape.event.imp;

import android.content.Intent;

import com.google.gson.Gson;
import com.iptv.grape.BaseActivity;
import com.iptv.grape.event.JSRequest;
import com.iptv.grape.event.msg.PageArgsData;
import com.iptv.grape.event.proc.IWebViewMessageProc;
import com.iptv.grape.jss.ThirdPartyAct;
import com.iptv.grape.util.AppLog;
import com.iptv.grape.video.XMediaPlayer;

public class OpenPage implements IWebViewMessageProc {

    PageArgsData argsData;
    @Override
    public void init(JSRequest jsRequest) {
        try {
            argsData = new Gson().fromJson(jsRequest.getJson(), PageArgsData.class);
        }
        catch (Exception e){
            argsData = null;
        }
    }
//    收到H5的消息：{"data":{"url":"http:\/\/117.158.207.135:9876\/","name":"天天乐园"},"id":"openPage"}
    @Override
    public String procMessage(BaseActivity baseActivity, XMediaPlayer mediaPlayer) {
        if(argsData != null){
            PageArgsData.PageArgsBean bean = argsData.getData();
            AppLog.getCurLog().out(bean.getUrl());
            //?UserId=xxx&UserToken=xxxx&PlatForm=zx
            //&UserId=xxx&UserToken=xxxx&PlatForm=zx
            // 拼接URL
            Intent intent = new Intent(baseActivity, ThirdPartyAct.class);
            intent.putExtra("url",bean.getUrl());
            intent.putExtra("name",bean.getName());
            intent.putExtra("video",true);
            baseActivity.startActivity(intent);

        }
        return "";
    }
}
